import request from "@/utils/request.ts";
import type {SysResponse} from "@/api/commonType.ts";
import type {AddMember, Member, MemberForm} from "@/api/member/type.ts";

export enum API {
  GET_MEMBERS = "/api/member/getMembers",
  UPDATE_MEMBER = "/api/member/update",
  SEARCH_MEMBER = "/api/member/search",
  DELETE_MEMBER = "/api/member/delete",
  ADD_MEMBER_TO_FAMILY = "/api/member/addToFamily",
}


/**
 * 获取家庭成员
 * @param familyId
 */
export function getMembersById(familyId: number) {
  return request.get<string, SysResponse<Member[]>>(API.GET_MEMBERS + `/${familyId}`)
}

/**
 * 修改家庭成员
 * @param member
 */
export function updateMember(member: Member) {
  return request.put<string, SysResponse<null>>(API.UPDATE_MEMBER + `/${member.id}`, member)
}


/**
 * 删除家庭成员
 * @param memberId
 * @param familyId
 */
export function deleteMemberById(familyId: number, memberId: number) {
  return request.delete<string, SysResponse<null>>(API.DELETE_MEMBER + `/${familyId}/${memberId}`)
}

/**
 * 搜索用户
 * @param content
 */
export function searchMember(content: string) {
  return request.get <string, SysResponse<MemberForm[]>>(API.SEARCH_MEMBER, {
    params: {
      content
    }
  })
}

/**
 * 添加成员
 * @param member
 */
export function addMemberToFamily(member: AddMember) {
  return request.post<string, SysResponse<null>>(API.ADD_MEMBER_TO_FAMILY, member);

}



